package Stack_Demo;

import java.util.Stack;

public class Test {
    public static void main1(String[] args) {
        Stack<Integer> stack =new Stack<>();
        stack.push(2);
        stack.push(3);
        stack.push(4);
        System.out.println(stack.pop());
    }

    public static void main(String[] args) {
        MyStack myStack = new MyStack();

    }
    public boolean isValid(String s) {
//        力扣 第二十题
        Stack<Character> stack = new Stack<>();
        for(int i = 0; i < s.length(); i++){
            char ch = s.charAt(i);
            if(ch == '(' || ch == '{' || ch == '['){
                stack.push(ch);
            } else {
                if(stack.isEmpty()){
                    return false;
                }
                char topChar = stack.pop();
                if((ch == ')' && topChar != '(') ||
                        (ch == '}' && topChar != '{') ||
                        (ch == ']' && topChar != '[')){
                    return false;
                }
            }
        }
        return stack.isEmpty();
    }
}
